var a = getApp(), t = require("../../component/WxNotificationCenter/WxNotificationCenter.js");

Page({
    data: {
        avatar: "/images/avatar.png",
        name: "点击登录",
        role: 100,
        scheduleCount: "0",
        fadanCount: "0",
        fansCount: "0",
        sortCount: "0",
        teamId: "",
        teamName: "",
        needUpdate: !1
    },
    bindEditInfoTap: function() {
        a.util.isLoginPage() && wx.navigateTo({
            url: "editInfo/editInfo"
        });
    },
    bindScheduleTap: function() {
        a.util.isLoginPage() && wx.switchTab({
            url: "../schedule/schedule"
        });
    },
    bindSendOrderTap: function() {
        a.util.isLoginPage() && wx.navigateTo({
            url: "/pages/sendOrder/sendList/sendList"
        });
    },
    bindFansTap: function() {
        a.util.isLoginPage() && wx.navigateTo({
            url: "fans/fans"
        });
    },
    bindSortTap: function() {
        a.util.isLoginPage() && wx.navigateTo({
            url: "rank/rank"
        });
    },
    bindVipTap: function() {
        a.util.isLoginPage() && wx.navigateTo({
            url: "vip/vip"
        });
    },
    bindUserHomeTap: function() {
        a.util.isLoginPage() && a.util.navToUserHome(a.globalData.accessToken);
    },
    bindTeamHomeTap: function() {
        a.util.isLoginPage() && (wx.getStorageSync(a.storage.meInfo).teamId.length > 0 ? wx.navigateTo({
            url: "team/team"
        }) : a.util.showToast("未加入团队"));
    },
    bindMeQiangdanTap: function() {
        a.util.isLoginPage() && wx.navigateTo({
            url: "myOrder/myOrder"
        });
    },
    bindAttentionTap: function() {
        a.util.isLoginPage() && wx.navigateTo({
            url: "attention/attention"
        });
    },
    bindSetTap: function() {
        a.util.isLoginPage() && wx.navigateTo({
            url: "set/set"
        });
    },
    bindInviteTap: function() {
        a.util.isLoginPage() && wx.navigateTo({
            url: "hyinvite/hyinvite"
        });
    },
    loadData: function() {
        if (a.util.isLogin()) {
            var t = this;
            a.network.post({
                url: a.url.getMeInfo,
                params: {},
                before: function() {
                    wx.showNavigationBarLoading();
                },
                success: function(n) {
                    1 == n.data.result ? (t.showData(n.data.data), wx.setStorageSync(a.storage.meInfo, n.data.data)) : a.util.showToast(n.data.message);
                },
                fail: function() {
                    a.util.showToast("获取个人信息失败");
                },
                complete: function() {
                    wx.hideNavigationBarLoading(), wx.stopPullDownRefresh();
                }
            });
        }
    },
    showData: function(a) {
        this.setData({
            avatar: a.avatar,
            name: a.name,
            role: a.role,
            scheduleCount: a.scheduleCount,
            fadanCount: a.searchScheduleCount,
            fansCount: a.fansCount,
            sortCount: a.sort,
            teamId: a.teamId,
            teamName: a.teamName
        });
    },
    didLogout: function() {
        this.setData({
            avatar: "/images/avatar.png",
            name: "点击登录",
            role: 100,
            scheduleCount: "0",
            fadanCount: "0",
            fansCount: "0",
            sortCount: "0",
            teamId: "",
            teamName: ""
        });
    },
    getData: function() {
        if (a.util.isLogin()) {
            a.network.post({
                url: a.url.userInfo,
                params: {},
                before: function() {},
                success: function(t) {
                    if (1 == t.data.result) {
                        t.data.data;
                        a.globalData.userInfo = t.data.data.info, wx.setStorageSync(a.storage.userInfo, t.data.data);
                    }
                },
                fail: function() {},
                complete: function() {
                    wx.hideLoading();
                }
            });
        }
    },
    onLoad: function(a) {
        t.addNotification("logoutSuccess", this.didLogout, this), t.addNotification("didLoginSuccess", this.loadData, this), 
        this.getData();
    },
    onReady: function() {
        if (a.log("onReady"), a.util.isLogin()) {
            var t = wx.getStorageSync(a.storage.meInfo);
            console.log("meInfoData", t), t && this.showData(t), this.loadData();
        }
    },
    onShow: function() {
        a.globalData.currentTab = "/pages/me/me", wx.showTabBar({}), a.util.isFirstLogin() && this.loadData(), 
        this.data.needUpdate && (this.loadData(), this.setData({
            needUpdate: !1
        }));
    },
    onHide: function() {
        a.log("onHide");
    },
    onUnload: function() {
        t.removeNotification("logoutSuccess", this), t.removeNotification("didLoginSuccess", this);
    },
    onPullDownRefresh: function() {
        a.log("onPullDownRefresh"), wx.stopPullDownRefresh();
    },
    onReachBottom: function() {},
    onShareAppMessage: function() {
        var t = a.util.getShareInfo();
        return {
            title: a.globalData.commonShareTitle,
            path: t[0],
            imageUrl: t[1],
            success: function(a) {},
            fail: function(a) {}
        };
    }
});